package cn.fbs.controller.core;

import cn.fbs.model.TImageInfo;
import cn.fbs.param.ImageParam;
import cn.fbs.service.core.ImageService;
import cn.fbs.vo.QueryPhotoVo;
import cn.fbs.vo.TImageItemVo;
import cn.fbs.vo.TProductInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;

import static cn.fbs.util.RequestUtils.getUserName;

@Api(tags = "图像管理")
@RestController
@RequestMapping()
public class ImageController {
    @Autowired
    private ImageService imageService;

    @ApiOperation("新增ZC图像")
    @PostMapping("imageData/addZCImage")
    public String addZCImage(@RequestBody ImageParam uploadParam,HttpServletRequest request) {
        try {
            uploadParam.setId(null);
            uploadParam.setIsExamine(1);
            uploadParam.setOperator(getUserName(request));
            return imageService.uploadImage(uploadParam);
        } catch (IOException e) {
            e.printStackTrace();
            return e.getMessage();
        }
    }



    @ApiOperation("批量新增ZC图像信息-以数组形式传和原来单个新增一样的数据")
    @PostMapping("imageData/batchAddImage")
    public String batchAddImage(@RequestBody List<ImageParam> list,HttpServletRequest request) throws IOException {
        for (ImageParam uploadParam : list) {
            uploadParam.setId(null);
            uploadParam.setIsExamine(1);
            uploadParam.setOperator(getUserName(request));

        }
        return imageService.batchUploadImage(list);
    }
    @ApiOperation("ZC图像检索 --新")
    @GetMapping("imageData/queryPhotoByParam")
    public List<TImageInfo> queryPhotoByParam(QueryPhotoVo photoVo) {
        List<TImageInfo> list = imageService.queryPhotoByParam(photoVo);
        return list;
    }

    @ApiOperation("编辑ZC图像")
    @PostMapping("imageData/updateZCImage")
    public String updateZCImage(@RequestBody ImageParam uploadParam, HttpServletRequest request) throws IOException {
        uploadParam.setIsExamine(null);
        uploadParam.setOperator(getUserName(request));
        return imageService.updateZCImage(uploadParam);
    }


    @ApiOperation("根据文件名词搜索当前目标下的图像")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "targetType", value = "目标序号"),
            @ApiImplicitParam(name = "imageName", value = "图像名称")}
    )
    @GetMapping("imageData/searchImage")
    public List<TProductInfoVo> searchImage(String targetType, String imageName) {
        return imageService.searchImage(targetType, imageName);
    }

    @ApiOperation("ZC图像基本详情")
    @GetMapping("imageData/ZCImageItem")
    @ApiImplicitParam(name = "id", value = "图像ID")
    public TImageItemVo getImageItem(@RequestParam("id") Integer id) {
        return imageService.getImageItem(id);
    }


}
